﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace ParticlePlayground
{
	// Token: 0x02000161 RID: 353
	[Serializable]
	public class ParticleStateC
	{
		// Token: 0x0600082F RID: 2095 RVA: 0x00030144 File Offset: 0x0002E344
		public virtual bool IsInitializing()
		{
			return this.isInitializing;
		}

		// Token: 0x06000830 RID: 2096 RVA: 0x0003014C File Offset: 0x0002E34C
		public virtual void Initialize()
		{
			this.isInitializing = true;
			if (this.stateMesh == null && this.stateTexture != null)
			{
				this.ConstructParticles(this.stateTexture, this.stateScale, this.stateOffset, this.stateName, this.stateTransform);
			}
			else if (this.stateMesh != null && this.stateTexture != null)
			{
				this.ConstructParticles(this.stateMesh, this.stateTexture, this.stateScale, this.stateOffset, this.stateName, this.stateTransform);
			}
			else if (this.stateMesh != null && this.stateTexture == null)
			{
				this.ConstructParticles(this.stateMesh, this.stateScale, this.stateOffset, this.stateName, this.stateTransform);
			}
			else
			{
				global::Debug.Log("State Texture or State Mesh returned null. Please assign an object to State: " + this.stateName + ".");
			}
			this.initialized = (this.position != null && this.position.Length > 0);
			this.isInitializing = false;
		}

		// Token: 0x06000831 RID: 2097 RVA: 0x00030288 File Offset: 0x0002E488
		public virtual void UpdateMatrix(bool isLocal)
		{
			this.stateTransformMx.SetTRS((!isLocal) ? this.stateTransform.position : Vector3.zero, (!isLocal) ? this.stateTransform.rotation : Quaternion.identity, (this.stateScaleMethod != ScaleMethod.Local) ? this.stateTransform.lossyScale : this.stateTransform.localScale);
		}

		// Token: 0x06000832 RID: 2098 RVA: 0x000302FC File Offset: 0x0002E4FC
		public virtual void ConstructParticles(Texture2D image, float scale, Vector3 offset, string newStateName, Transform newStateTransform)
		{
			List<Color32> list = new List<Color32>();
			List<Vector3> list2 = new List<Vector3>();
			this.color = PlaygroundC.GetPixels(image);
			bool flag = false;
			if (PlaygroundC.reference)
			{
				flag = PlaygroundC.reference.buildZeroAlphaPixels;
			}
			bool flag2 = this.stateDepthmap != null;
			Color32[] array = (!flag2) ? null : PlaygroundC.GetPixels(this.stateDepthmap);
			int num = 0;
			int num2 = 0;
			float num3 = (!(this.stateDepthmap != null)) ? 0f : ((float)array.Length * 1f / ((float)this.color.Length * 1f));
			byte b = (byte)(this.chromaKeySpread * 255f);
			for (int i = 0; i < this.color.Length; i++)
			{
				if ((flag || this.color[i].a != 0) && (!this.applyChromaKey || (this.applyChromaKey && (this.color[i].r < this.chromaKey.r - b || this.color[i].r > this.chromaKey.r + b) && (this.color[i].g < this.chromaKey.g - b || this.color[i].g > this.chromaKey.g + b) && (this.color[i].b < this.chromaKey.b - b || this.color[i].b > this.chromaKey.b + b))))
				{
					list.Add(this.color[i]);
					if (flag2)
					{
						int num4 = Mathf.FloorToInt((float)i * 1f * num3);
						float z = ((float)array[num4].r * 1f + (float)array[num4].g * 1f + (float)array[num4].b * 1f) / 3f * ((float)array[num4].a * 1f / 255f) * this.stateDepthmapStrength / 255f;
						list2.Add(new Vector3((float)num, (float)num2, z));
					}
					else
					{
						list2.Add(new Vector3((float)num, (float)num2, 0f));
					}
				}
				num++;
				num %= image.width;
				if (num == 0 && i != 0)
				{
					num2++;
				}
			}
			this.color = list.ToArray();
			this.position = list2.ToArray();
			this.normals = new Vector3[this.position.Length];
			for (int j = 0; j < this.normals.Length; j++)
			{
				this.normals[j] = Vector3.forward;
			}
			this.stateTransform = newStateTransform;
			this.stateTexture = image;
			this.colorLength = this.color.Length;
			this.positionLength = this.position.Length;
			this.stateScale = scale;
			this.stateOffset = offset;
			this.stateName = newStateName;
			this.initialized = (this.position.Length > 0);
		}

		// Token: 0x06000833 RID: 2099 RVA: 0x0003068C File Offset: 0x0002E88C
		public virtual void ConstructParticles(Mesh mesh, Texture2D texture, float scale, Vector3 offset, string newStateName, Transform newStateTransform)
		{
			this.position = mesh.vertices;
			this.normals = mesh.normals;
			if (this.normals == null || this.normals.Length == 0)
			{
				this.normals = new Vector3[this.position.Length];
				for (int i = 0; i < this.normals.Length; i++)
				{
					this.normals[i] = Vector3.forward;
				}
			}
			Vector2[] uv = mesh.uv;
			this.color = new Color32[uv.Length];
			for (int j = 0; j < this.position.Length; j++)
			{
				this.color[j] = texture.GetPixelBilinear(uv[j].x, uv[j].y);
			}
			this.stateMesh = mesh;
			this.stateTransform = newStateTransform;
			this.colorLength = this.color.Length;
			this.positionLength = this.position.Length;
			this.stateScale = scale;
			this.stateOffset = offset;
			this.stateName = newStateName;
			this.initialized = (this.position.Length > 0);
		}

		// Token: 0x06000834 RID: 2100 RVA: 0x000307C0 File Offset: 0x0002E9C0
		public virtual void ConstructParticles(Mesh mesh, float scale, Vector3 offset, string newStateName, Transform newStateTransform)
		{
			this.position = mesh.vertices;
			this.normals = mesh.normals;
			if (this.normals == null || this.normals.Length == 0)
			{
				this.normals = new Vector3[this.position.Length];
				for (int i = 0; i < this.normals.Length; i++)
				{
					this.normals[i] = Vector3.forward;
				}
			}
			Vector2[] uv = mesh.uv;
			this.color = new Color32[uv.Length];
			this.stateMesh = mesh;
			this.stateTransform = newStateTransform;
			this.colorLength = this.color.Length;
			this.positionLength = this.position.Length;
			this.stateScale = scale;
			this.stateOffset = offset;
			this.stateName = newStateName;
			this.initialized = (this.position.Length > 0);
		}

		// Token: 0x06000835 RID: 2101 RVA: 0x000308A8 File Offset: 0x0002EAA8
		public virtual Color32 GetColor(int index)
		{
			if (this.colorLength == 0)
			{
				return default(Color32);
			}
			index %= this.colorLength;
			return this.color[index];
		}

		// Token: 0x06000836 RID: 2102 RVA: 0x000308E8 File Offset: 0x0002EAE8
		public virtual Vector3 GetPosition(int index)
		{
			if (this.positionLength == 0)
			{
				return default(Vector3);
			}
			index %= this.positionLength;
			return (this.position[index] + this.stateOffset) * this.stateScale;
		}

		// Token: 0x06000837 RID: 2103 RVA: 0x0003093C File Offset: 0x0002EB3C
		public virtual Vector3 GetLocalPosition(int index)
		{
			if (this.positionLength == 0)
			{
				return default(Vector3);
			}
			index %= this.positionLength;
			return this.stateTransformMx.MultiplyPoint3x4((this.position[index] + this.stateOffset) * this.stateScale);
		}

		// Token: 0x06000838 RID: 2104 RVA: 0x0003099C File Offset: 0x0002EB9C
		public virtual Vector3 GetNormal(int index)
		{
			if (this.positionLength == 0)
			{
				return default(Vector3);
			}
			index %= this.positionLength;
			return this.normals[index];
		}

		// Token: 0x06000839 RID: 2105 RVA: 0x000309DC File Offset: 0x0002EBDC
		public virtual Vector3 GetLocalNormal(int index)
		{
			if (this.positionLength == 0)
			{
				return default(Vector3);
			}
			index %= this.positionLength;
			return this.stateTransformMx.MultiplyPoint3x4(this.normals[index]);
		}

		// Token: 0x0600083A RID: 2106 RVA: 0x00030A24 File Offset: 0x0002EC24
		public virtual Color32[] GetColors()
		{
			return this.color.Clone() as Color32[];
		}

		// Token: 0x0600083B RID: 2107 RVA: 0x00030A38 File Offset: 0x0002EC38
		public virtual Vector3[] GetPositions()
		{
			return this.position.Clone() as Vector3[];
		}

		// Token: 0x0600083C RID: 2108 RVA: 0x00030A4C File Offset: 0x0002EC4C
		public virtual Vector3[] GetNormals()
		{
			return this.normals.Clone() as Vector3[];
		}

		// Token: 0x0600083D RID: 2109 RVA: 0x00030A60 File Offset: 0x0002EC60
		public virtual void SetColor(int index, Color32 c)
		{
			this.color[index] = c;
		}

		// Token: 0x0600083E RID: 2110 RVA: 0x00030A74 File Offset: 0x0002EC74
		public virtual void SetPosition(int index, Vector3 v)
		{
			this.position[index] = v;
		}

		// Token: 0x0600083F RID: 2111 RVA: 0x00030A88 File Offset: 0x0002EC88
		public virtual void SetNormal(int index, Vector3 v)
		{
			this.normals[index] = v;
		}

		// Token: 0x06000840 RID: 2112 RVA: 0x00030A9C File Offset: 0x0002EC9C
		public virtual Vector3 GetParentedPosition(int thisPosition)
		{
			thisPosition %= this.positionLength;
			return this.stateTransform.TransformPoint((this.position[thisPosition] + this.stateOffset) * this.stateScale);
		}

		// Token: 0x06000841 RID: 2113 RVA: 0x00030ADC File Offset: 0x0002ECDC
		public virtual ParticleStateC Clone()
		{
			return new ParticleStateC
			{
				stateName = this.stateName,
				stateScale = this.stateScale,
				stateTexture = this.stateTexture,
				stateDepthmap = this.stateDepthmap,
				stateDepthmapStrength = this.stateDepthmapStrength,
				stateMesh = this.stateMesh,
				stateOffset = this.stateOffset,
				colorLength = this.colorLength,
				positionLength = this.positionLength,
				stateTransform = this.stateTransform,
				applyChromaKey = this.applyChromaKey,
				chromaKey = this.chromaKey,
				chromaKeySpread = this.chromaKeySpread
			};
		}

		// Token: 0x0400081D RID: 2077
		protected Color32[] color;

		// Token: 0x0400081E RID: 2078
		protected Vector3[] position;

		// Token: 0x0400081F RID: 2079
		protected Vector3[] normals;

		// Token: 0x04000820 RID: 2080
		public Texture2D stateTexture;

		// Token: 0x04000821 RID: 2081
		public Texture2D stateDepthmap;

		// Token: 0x04000822 RID: 2082
		public float stateDepthmapStrength = 1f;

		// Token: 0x04000823 RID: 2083
		public Mesh stateMesh;

		// Token: 0x04000824 RID: 2084
		public string stateName;

		// Token: 0x04000825 RID: 2085
		public float stateScale = 1f;

		// Token: 0x04000826 RID: 2086
		public Vector3 stateOffset;

		// Token: 0x04000827 RID: 2087
		public Transform stateTransform;

		// Token: 0x04000828 RID: 2088
		public Matrix4x4 stateTransformMx = default(Matrix4x4);

		// Token: 0x04000829 RID: 2089
		public ScaleMethod stateScaleMethod;

		// Token: 0x0400082A RID: 2090
		[NonSerialized]
		public bool initialized;

		// Token: 0x0400082B RID: 2091
		[HideInInspector]
		public int colorLength;

		// Token: 0x0400082C RID: 2092
		[HideInInspector]
		public int positionLength;

		// Token: 0x0400082D RID: 2093
		[HideInInspector]
		public bool applyChromaKey;

		// Token: 0x0400082E RID: 2094
		[HideInInspector]
		public Color32 chromaKey;

		// Token: 0x0400082F RID: 2095
		[HideInInspector]
		public float chromaKeySpread;

		// Token: 0x04000830 RID: 2096
		protected bool isInitializing;
	}
}
